bitkeeper revision 1.1159.170.93 (41e661e138UbGRYHtgaE3FTrqTgzzw)
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Thu, 13 Jan 2005 11:56:17 +0000 (11:56 +0000)
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Thu, 13 Jan 2005 11:56:17 +0000 (11:56 +0000)
Add VIF-routing capability to xend. The default is still to bridge.

.rootkeys
tools/examples/Makefile
tools/examples/network-route [new file with mode: 0755]
tools/examples/vif-route [new file with mode: 0755]
tools/examples/xend-config.sxp
tools/python/xen/xm/create.py

index 89187e42af6e1e245b925f53e3f5f7218938fcac..9f7ea4cd178bf9ec7f4dcadf5b1a31cdab76639d 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
 405ff55dawQyCHFEnJ067ChPRoXBBA tools/examples/init.d/xend
 40278d94cIUWl2eRgnwZtr4hTyWT1Q tools/examples/init.d/xendomains
 40ee75a9xFz6S05sDKu-JCLqyVTkDA tools/examples/network
+41e661e1giIEKbJ25qfiP-ke8u8hFA tools/examples/network-route
 40ee75a967sxgcRY4Q7zXoVUaJ4flA tools/examples/vif-bridge
+41e661e1ooiRKlOfwumG6wwzc0PdhQ tools/examples/vif-route
 40ee75a93cqxHp6MiYXxxwR5j2_8QQ tools/examples/xend-config.sxp
 41090ec8Pj_bkgCBpg2W7WfmNkumEA tools/examples/xmexample1
 40cf2937oKlROYOJTN8GWwWM5AmjBg tools/examples/xmexample2
index 1e77f89d5023c2ea3f41c1631b66e7262f30e43d..14f18ae84fc72e82883bebbed330c31248e7b06c 100644 (file)
@@ -11,8 +11,8 @@ XEN_CONFIGS += xmexample2
 
 # Xen script dir and scripts to go there.
 XEN_SCRIPT_DIR = /etc/xen/scripts
-XEN_SCRIPTS = network
-XEN_SCRIPTS += vif-bridge
+XEN_SCRIPTS = network vif-bridge
+XEN_SCRIPTS += network-route vif-route
 XEN_SCRIPTS += block-file
 XEN_SCRIPTS += block-enbd
 
diff --git a/tools/examples/network-route b/tools/examples/network-route
new file mode 100755 (executable)
index 0000000..cb217c0
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+#============================================================================
+# Default Xen network start/stop script.
+# Xend calls a network script when it starts.
+# The script name to use is defined in /etc/xen/xend-config.sxp
+# in the network-script field.
+#
+# Usage:
+#
+# network-route (start|stop|status) {VAR=VAL}*
+#
+# Vars:
+#
+# netdev     The gateway interface (default eth0).
+# antispoof  Whether to use iptables to prevent spoofing (default yes).
+#
+#============================================================================
+
+echo 1 >/proc/sys/net/ipv4/ip_forward
diff --git a/tools/examples/vif-route b/tools/examples/vif-route
new file mode 100755 (executable)
index 0000000..b15aea1
--- /dev/null
@@ -0,0 +1,76 @@
+#!/bin/sh
+#============================================================================
+# /etc/xen/vif-route
+#
+# Script for configuring a vif in routed mode.
+# Xend calls a vif script when bringing a vif up or down.
+# This script is the default - but it can be configured for each vif.
+#
+# Example invocation:
+#
+# vif-route up domain=VM1 vif=vif1.0 ip="128.232.38.45/28 10.10.10.55/24"
+#
+# Usage:
+# vif-route (up|down) {VAR=VAL}*
+#
+# Vars:
+#
+# domain  name of the domain the interface is on (required).
+# vif     vif interface name (required).
+# mac     vif MAC address (required).
+# ip      list of IP networks for the vif, space-separated (optional).
+#============================================================================
+
+# Exit if anything goes wrong
+set -e 
+
+echo "vif-route $*"
+
+# Operation name.
+OP=$1
+shift
+
+# Pull variables in args into environment
+for arg ; do export "${arg}" ; done
+
+# Required parameters. Fail if not set.
+domain=${domain:?}
+vif=${vif:?}
+mac=${mac:?}
+
+# Optional parameters. Set defaults.
+ip=${ip:-''}   # default to null (do nothing)
+
+main_ip=`ifconfig eth0 | grep "inet addr:" | sed -e 's/.*inet addr:\(\w\w*\.\w\w*\.\w\w*\.\w\w*\).*/\1/'`
+
+# Are we going up or down?
+case $OP in
+    up)
+        ifconfig ${vif} 169.254.1.0 netmask 255.255.255.255 up
+        echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
+        iptcmd='-A'
+        ipcmd='a'
+        ;;
+    down)
+        ifconfig ${vif} down
+        iptcmd='-D'
+        ipcmd='d'
+        ;;
+    *)
+        echo 'Invalid command: ' $OP
+        echo 'Valid commands are: up, down'
+        exit 1
+        ;;
+esac
+
+if [ ${ip} ] ; then
+
+    # If we've been given a list of IP networks, allow pkts with these src addrs.
+    for addr in ${ip} ; do
+      ip r ${ipcmd} ${addr} dev ${vif} src ${main_ip}
+#      iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -s ${addr} -j ACCEPT
+    done 
+
+    # Always allow us to talk to a DHCP server anyhow.
+#    iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -p udp --sport 68 --dport 67 -j ACCEPT
+fi
index ee5dbbc0a355448bc70506e57894b967780f2cb0..a62b112519122b7d667d15c03d717feeb7b27151 100644 (file)
@@ -8,12 +8,17 @@
 # Specifying the empty string '' allows all connections.
 (xend-address      '')
 
+## Use the following if VIF traffic is routed.
 # The script used to start/stop networking for xend.
-(network-script    network)
+#(network-script     network-route)
+# The default script used to control virtual interfaces.
+#(vif-script         vif-route)
 
+## Use the following if VIF traffic is bridged.
+# The script used to start/stop networking for xend.
+(network-script    network)
 # The default bridge that virtual interfaces should be connected to.
 (vif-bridge        xen-br0)
-
 # The default script used to control virtual interfaces.
 (vif-script        vif-bridge)
 
index 9d977dd337104d5af77b5b1c60d59760911de861..03f815eddb1d0110acc4bb83a501297466c2be51 100644 (file)
@@ -283,14 +283,18 @@ def configure_vifs(config_devs, vals):
         if idx < len(vifs):
             d = vifs[idx]
             mac = d.get('mac')
+            if not mac:
+                mac = randomMAC()
             bridge = d.get('bridge')
             script = d.get('script')
             backend = d.get('backend')
+            ip = d.get('ip')
         else:
             mac = randomMAC()
             bridge = None
             script = None
             backend = None
+            ip = None
         config_vif = ['vif']
         config_vif.append(['mac', mac])
         if bridge:
@@ -299,6 +303,8 @@ def configure_vifs(config_devs, vals):
             config_vif.append(['script', script])
         if backend:
             config_vif.append(['backend', backend])
+        if ip:
+            config_vif.append(['ip', ip])
         config_devs.append(['device', config_vif])
 
 def configure_vfr(config, vals):
@@ -377,7 +383,7 @@ def preprocess_vifs(opts, vals):
             (k, v) = b.strip().split('=', 1)
             k = k.strip()
             v = v.strip()
-            if k not in ['mac', 'bridge', 'script', 'backend']:
+            if k not in ['mac', 'bridge', 'script', 'backend', 'ip']:
                 opts.err('Invalid vif specifier: ' + vif)
             d[k] = v
         vifs.append(d)